import modelExtend from '@/utils/modelExtend';
import HttpModel from '@/models/http';
import { doPostToObj } from '@/services/http';

let dataClassificationManagement = {
  namespace: 'dataClassificationManagement',
  effects: {
    *postFetchPage({ payload, callback }, { call, put }) {
      const initParams = Object.assign(
        {
          number: 1,
          size: 10,
        },
        payload,
      );
      const response = yield call(doPostToObj, initParams);
      if (response.statusCode === '0') {
        const { data = {} } = response;
        const pageData = {
          list: response.data?.content ?? [],
          pagination: {
            total: data?.totalElements ?? 0,
            current: (data?.number ?? 0) + 1,
            pageSize: data?.size ?? 10,
          },
        };
        yield put({ type: 'req', payload: { pageData: pageData } });
        if (callback) callback(response);
        return response;
      }
    },
  },
};
dataClassificationManagement = modelExtend(HttpModel, dataClassificationManagement);
export default dataClassificationManagement;
